package com.game.server.message.proto.execute;

import com.comm.ISession;

import com.game.majiang.config.DataManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.dao.XyClubMemberInfoDao;
import com.game.server.db.entity.XyClubInfo;
import com.game.server.db.entity.XyClubMemberInfo;
import com.game.server.message.proto.in.AbstractXYclubPartnerCuttingReq;
import com.game.server.message.proto.out.XYclubPartnerCuttingRsp;

public class XYclubPartnerCuttingReq extends AbstractXYclubPartnerCuttingReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null&&client.checkClick(msgcode)) {
            XYclubPartnerCuttingRsp rsp = new XYclubPartnerCuttingRsp();
            rsp.setIsok(1);
            XyClubInfo xyClubInfo = DataManager.getInstance().getMapClub().get(this.clubid);
            if (xyClubInfo != null) {
                XyClubMemberInfo myMemberInfo = xyClubInfo.getPlayer().get(client.getUserId());
                if (myMemberInfo != null && (myMemberInfo.getIsManager() == 1 || myMemberInfo.getIsManager() == 2)) {
                    XyClubMemberInfo toMemberInfo = xyClubInfo.getPlayer().get(this.uid);
                    if (toMemberInfo != null && toMemberInfo.getIsAccessory() == 1) {
                        int updateBalanceBonus = toMemberInfo.updateBalanceBonus(this.value, 2,myMemberInfo.getUid(),0);
                        if (updateBalanceBonus==0){
                            rsp.setIsok(0);
                            rsp.setValue(this.value);
                        }else{
                            rsp.setIsok(updateBalanceBonus);
                        }
                    }
                }
            }
            client.Send(rsp);
        }
    }

}
